<?php
/**
 * 自定义标签
 * 上传图片
 */

namespace app\common\taglib;

use think\template\TagLib;

class Upfile extends TagLib
{
    /**
     * 定义标签
     * @var array
     */
    protected $tags = [
        /**标签定义
         * attr：属性列表
         * close：是否闭合（0表示闭合，1表示不闭合。默认值为1）
         * alias：标签别名
         * level：嵌套层次
         */
        'uploadfiletag' => ['attr' => 'tagid,name,url,multiple,file_limit,save,local', 'close' => 0],
        //tagid表示DIVID name表示input name url表示默认显示的图片地址（可为数组） multiple是否支持多个文件
        'uploadvideotag' => ['attr' => 'tagid,name,url,multiple,path,local', 'close' => 0],
        //tagid表示DIVID name表示input name url表示默认显示的图片地址（可为数组） multiple是否支持多个文件
        'uploadaudiotag' => ['attr' => 'tagid,name,url,multiple,path,local', 'close' => 0],
        //tagid表示DIVID name表示input name url表示默认显示的图片地址（可为数组） multiple是否支持多个视频
        'uploadtag' => ['attr' => 'tagid,name,url,multiple,file_limit,saveW,saveH,save,local', 'close' => 0],
        //tagid表示DIVID name表示input name url表示默认显示的图片地址（可为数组） multiple是否支持多张图片
        'ueditortag' => ['attr' => 'tagid,width,content,local', 'close' => 0],
        //tagid表示DIVID width表示宽度
    ];

    /**
     * 上传文件标签
     * @param $tag
     * @return string
     */
    public function tagUploadtag($tag)
    {
        global $globalConfig;
        $tag['save'] = $tag['save'] ?? 0;
        $tag['dir'] = $tag['dir'] ?? '';
        $tag['local'] = $tag['local'] ?? false;
        $ajaxurl = '{$Request.root}/index/upload?type=image&path=' . $tag['dir'] . '&save=' . $tag['save'] . '&local=' . $tag['local'];
        $tag['tagid'] = $tag['tagid'] ?? 'fileinput';//标签ID
        $tag['name'] = $tag['name'] ?? 'filename';//上传名称
        $sid = $tag['tagid'] . 'sid';
        $tag['multiple'] = $tag['multiple'] ?? 'false';
        if ($tag['multiple'] == 'true') {
            $tag['name'] .= '[]';
        }
        $tag['saveW'] = $tag['saveW'] ?? 0;//高度
        $tag['saveH'] = $tag['saveH'] ?? 0;//图片高度
        if ($tag['saveW'] || $tag['saveH']) {
            $parse = '<button type="button" class="pear-btn pear-btn-primary pear-btn-sm upload-image" id="cropper_' . $tag['tagid'] . '">';
        } else {
            $parse = '<button type="button" class="pear-btn pear-btn-primary pear-btn-sm upload-image" id="' . $tag['tagid'] . '">';
        }
        $parse .= '<i class="fa fa-image"></i>上传图片';
        $parse .= '</button>';
        $parse .= '<div class="upload-image" style="display:inline-flex;flex-wrap: wrap;" id="' . $sid . '">';
        if ($tag['url']) {
            $parse .= '<?php ';
            $parse .= '$__LIST__ = ' . $tag['url'] . ' ? ' . $tag['url'] . ' : [] ;';
            $parse .= '$__LIST__ = is_array($__LIST__) ? $__LIST__ : [$__LIST__];';
            $parse .= ' ?>';
            $parse .= '{volist name="__LIST__" id="val"}';
            $parse .= '<div class="updiv" style="position: relative;margin-left: 5px;"><input type="hidden" name="' . $tag['name'] . '" value="{$val}" /><a href="{$val}" target="_blank"><img src="{$val}" alt="{$val}" class="upload-image"></a><img width="15px" src="/static/admin/images/x.png" class="pos_close" style="position: absolute;right: 0px;top: 0px;" onclick="pos_close(this)"/></div>';
            $parse .= '{/volist}';
        }
        $parse .= '</div>';
        $parse .= '<script language="JavaScript" type="text/javascript" src="/static/admin/js/jquery.min.js"></script>';
        $parse .= '<script language="JavaScript" type="text/javascript" src="/static/component/layui/sortable.js"></script>';
        $parse .= '<script type="text/javascript">';
        $parse .= 'layui.use([\'upload\',\'common\'],function(){';
        $parse .= 'var upload = layui.upload;';
        $parse .= 'var common = layui.common;';
        $parse .= 'upload.render({';
        $parse .= 'elem: \'#' . $tag['tagid'] . '\',';
        $parse .= 'url: \'' . $ajaxurl . '\',';
        $parse .= 'accept:\'images\',';
        $parse .= "exts:'" . ($globalConfig['imgValidate_ext'] ?? 'jpg|png|jpeg|gif|bmp|svg') . "',";
        $parse .= "size:'" . ($globalConfig['imgValidate_size'] ?? '5120') . "',";
        $parse .= 'field:\'imageFile\',';
        $parse .= 'multiple:' . $tag['multiple'] . ',';
        $parse .= 'done: function(res){';
        $parse .= 'if(res.code==0){';
        //判断是否上传多张图片
        if ($tag['multiple'] == 'true') {
            $parse .= '$("#' . $sid . '").append(\'<div class="updiv" style="position: relative;margin-left: 5px;"><input type="hidden" name="' . $tag['name'] . '" value="\'+ res.data.src +\'" /><a href="\'+ res.data.src +\'" target="_blank"><img src="\'+ res.data.src +\'" alt="\'+ res.data.src +\'" class="upload-image"></a><img width="15px" src="/static/admin/images/x.png" class="pos_close" style="position: absolute;right: 0px;top: 0px;" onclick="pos_close(this)"/></div>\');';
        } else {
            $parse .= '$("#' . $sid . '").html(\'<div class="updiv" style="position: relative;margin-left: 5px;"><input type="hidden" name="' . $tag['name'] . '" value="\'+ res.data.src +\'" /><a href="\'+ res.data.src +\'" target="_blank"><img src="\'+ res.data.src +\'" alt="\'+ res.data.src +\'" class="upload-image"></a><img width="15px" src="/static/admin/images/x.png" class="pos_close" style="position: absolute;right: 0px;top: 0px;" onclick="pos_close(this)"/></div>\');';
        }
        $parse .= '}';
        $parse .= 'layer.msg(res.msg);';
        $parse .= '},';
        $parse .= 'error: function(res){';
        $parse .= 'console.log(res);';
        $parse .= 'layer.msg(\'上传失败！\');';
        $parse .= '}';
        $parse .= '});';
        $parse .= '$("#cropper_' . $tag['tagid'] . '").on(\'click\', function () {';
        $parse .= 'cropperImage(\'\');';
        $parse .= '});';
        $parse .= 'function cropperImage(image) {';
        $parse .= 'layer.open({';
        $parse .= 'type: 2,';
        $parse .= 'title: \'上传图片\',';
        $parse .= 'shade: 0.1,';
        $parse .= 'area: common.screenBig(),';
        $parse .= 'content:\'' . url('Index/imageCropper') . '?path=' . $tag['dir'] . '&save=' . $tag['save'] . '&width=' . $tag['saveW'] . '&height=' . $tag['saveH'] . '&image=\'+image,';
        $parse .= 'btn: [\'确定\', \'取消\'],';
        $parse .= 'yes: function (index, layero) {';
        $parse .= 'window[\'layui-layer-iframe\' + index].submitForm().then(function (result) {';
        $parse .= 'layer.close(index);';
        if ($tag['multiple'] == 'true') {
            $parse .= '$("#' . $sid . '").append(\'<div class="updiv" style="position: relative;margin-left: 5px;"><input type="hidden" name="' . $tag['name'] . '" value="\'+ result.src +\'" /><a href="\'+ result.src +\'" target="_blank"><img src="\'+ result.src +\'" alt="\'+ result.src +\'" class="upload-image"></a><img width="15px" src="/static/admin/images/x.png" class="pos_close" style="position: absolute;right: 0px;top: 0px;" onclick="pos_close(this)"/></div>\');';
        } else {
            $parse .= '$("#' . $sid . '").html(\'<div class="updiv" style="position: relative;margin-left: 5px;"><input type="hidden" name="' . $tag['name'] . '" value="\'+ result.src +\'" /><a href="\'+ result.src +\'" target="_blank"><img src="\'+ result.src +\'" alt="\'+ result.src +\'" class="upload-image"></a><img width="15px" src="/static/admin/images/x.png" class="pos_close" style="position: absolute;right: 0px;top: 0px;" onclick="pos_close(this)"/></div>\');';
        }
        $parse .= '});';
        $parse .= '}';
        $parse .= '});';
        $parse .= '}';
        $parse .= '});';
        $parse .= 'var pos_close = function(obj){';
        $parse .= '$(obj).parent().remove();';
//        $parse .= '$(obj).closest(".updiv").remove();';
        $parse .= '};';
        if ($tag['multiple'] == true) {
            $parse .= 'new Sortable(document.getElementById(\'' . $sid . '\'), {';
            $parse .= 'animation: 150,';
            $parse .= 'ghostClass: \'updiv\',';
            $parse .= '});';
        }
        $parse .= '</script>';

        return $parse;
    }

    /**
     * 上传视频标签
     * @param $tag
     * @return string
     */
    public function tagUploadVideotag($tag)
    {
        global $globalConfig;
        $tag['dir'] = $tag['dir'] ?? '';
        $tag['local'] = $tag['local'] ?? false;
        $ajaxurl = '{$Request.root}/index/upload?type=video&path=' . $tag['dir'] . '&local=' . $tag['local'];
        $tag['tagid'] = $tag['tagid'] ?? 'fileinput';//标签ID
        $tag['name'] = $tag['name'] ?? 'filename';//上传名称
        $sid = $tag['tagid'] . 'sid';
        $tag['multiple'] = $tag['multiple'] ?? 'false';
        if ($tag['multiple'] == 'true') {
            $tag['name'] .= '[]';
        }
        $parse = '<button type="button" class="pear-btn pear-btn-primary pear-btn-sm upload-image" id="' . $tag['tagid'] . '">';
        $parse .= '<i class="fa fa-image"></i>上传视频';
        $parse .= '</button>';
        $parse .= '<div class="upload-image" style="display:inline-flex;flex-wrap: wrap;" id="' . $sid . '">';
        if ($tag['url']) {
            $parse .= '<?php ';
            $parse .= '$__LIST__ = ' . $tag['url'] . ' ? ' . $tag['url'] . ' : [] ;';
            $parse .= '$__LIST__ = is_array($__LIST__) ? $__LIST__ : [$__LIST__];';
            $parse .= ' ?>';
            $parse .= '{volist name="__LIST__" id="val"}';
            $parse .= '<div class="updiv" style="position: relative;margin-left: 5px;"><input type="hidden" name="' . $tag['name'] . '" value="{$val}" /><a href="{$val}" target="_blank"><video src="{$val}" alt="{$val}" class="upload-image" style="width: 75px;height: 50px;background-color:antiquewhite;"></a><img width="15px" src="/static/admin/images/x.png" class="pos_close" style="position: absolute;right: 0px;top: 0px;" onclick="pos_close(this)"/></div>';

            $parse .= '{/volist}';
        }
        $parse .= '</div>';
        $parse .= '<script language="JavaScript" type="text/javascript" src="/static/admin/js/jquery.min.js"></script>';
        $parse .= '<script type="text/javascript">';
        $parse .= 'layui.use([\'upload\',\'element\'],function(){';
        $parse .= 'var upload = layui.upload;';
        $parse .= 'var element = layui.element;';
        $parse .= 'let progress = \'' . randString(6) . '\';';
        $parse .= 'upload.render({';
        $parse .= 'elem: \'#' . $tag['tagid'] . '\',';
        $parse .= 'url: \'' . $ajaxurl . '\',';
        $parse .= 'accept:\'video\',';
        $parse .= "exts:'" . ($globalConfig['videoValidate_ext'] ?? 'mkv|mp4|avi|rm|rmvb|mp3|m4v') . "',";
        $parse .= "size:'" . ($globalConfig['videoValidate_size'] ?? '512000') . "',";
        $parse .= 'multiple:' . $tag['multiple'] . ',';
        $parse .= 'done: function(res){';
        $parse .= 'if(res.code==0){';
        $parse .= '$(".updiv"+ progress).remove();';
        //判断是否上传多张图片
        if ($tag['multiple'] == 'true') {
            $parse .= '$("#' . $sid . '").append(\'<div class="updiv" style="position: relative;margin-left: 5px;"><input type="hidden" name="' . $tag['name'] . '" value="\'+ res.data.src +\'" /><a href="\'+ res.data.src +\'" target="_blank"><video src="\'+ res.data.src +\'" alt="\'+ res.data.src +\'" class="upload-image" style="width: 75px;height: 50px;background-color:antiquewhite;"></a><img width="15px" src="/static/admin/images/x.png" class="pos_close" style="position: absolute;right: 0px;top: 0px;" onclick="pos_close(this)"/></div>\');';
        } else {
            $parse .= '$("#' . $sid . '").html(\'<div class="updiv" style="position: relative;margin-left: 5px;"><input type="hidden" name="' . $tag['name'] . '" value="\'+ res.data.src +\'" /><a href="\'+ res.data.src +\'" target="_blank"><video src="\'+ res.data.src +\'" alt="\'+ res.data.src +\'" class="upload-image" style="width: 75px;height: 50px;background-color:antiquewhite;"></a><img width="15px" src="/static/admin/images/x.png" class="pos_close" style="position: absolute;right: 0px;top: 0px;" onclick="pos_close(this)"/></div>\');';
        }
        $parse .= '}';
        $parse .= 'layer.msg(res.msg);';
        $parse .= '},';
        $parse .= 'before: function(obj){';
        if ($tag['multiple'] == 'true') {
            $parse .= '$("#' . $sid . '").append(\'<div class="updiv\'+ progress +\'" style="position: relative;margin-left: 5px;"><div class="layui-progress" style="width: 75px;height: 50px;background-color:antiquewhite;border-radius: 0px;" lay-showPercent="true" lay-filter="filter-demo-\'+ progress +\'"><div class="layui-progress-bar" style="position: absolute;top: 45%;" lay-percent="0%"></div></div></div>\');';
        } else {
            $parse .= '$("#' . $sid . '").html(\'<div class="updiv\'+ progress +\'" style="position: relative;margin-left: 5px;"><div class="layui-progress" style="width: 75px;height: 50px;background-color:antiquewhite;border-radius: 0px;" lay-showPercent="true" lay-filter="filter-demo-\'+ progress +\'"><div class="layui-progress-bar" style="position: absolute;top: 45%;" lay-percent="0%"></div></div></div>\');';
        }
        $parse .= '},';
        $parse .= 'progress: function(n, elem, e){';
        $parse .= 'var percent = n + \'%\';';
        $parse .= 'element.progress("filter-demo-"+ progress, percent);';
        $parse .= '},';
        $parse .= 'error: function(){';
        $parse .= 'layer.msg(\'上传失败！\');';
        $parse .= '}';
        $parse .= '});';
        $parse .= '});';
        $parse .= 'var pos_close = function(obj){';
        $parse .= '$(obj).closest(".updiv").remove()';
        $parse .= '}';
        $parse .= '</script>';
        return $parse;
    }

    /**
     * 上传文件标签
     * @param $tag
     * @return string
     */
    public function tagUploadFiletag($tag)
    {
        global $globalConfig;
        $tag['dir'] = $tag['dir'] ?? '';
        $tag['local'] = $tag['local'] ?? false;
        $ajaxurl = '{$Request.root}/index/upload?type=file&path=' . $tag['dir'] . '&local=' . $tag['local'];
        $tag['tagid'] = $tag['tagid'] ?? 'fileinput';//标签ID
        $tag['name'] = $tag['name'] ?? 'filename';//上传名称
        $sid = $tag['tagid'] . 'sid';
        $tag['multiple'] = $tag['multiple'] ?? 'false';
        if ($tag['multiple'] == 'true') {
            $tag['name'] .= '[]';
        }
        $parse = '<button type="button" class="pear-btn pear-btn-primary pear-btn-sm upload-image" id="' . $tag['tagid'] . '">';
        $parse .= '<i class="fa fa-image"></i>上传文件';
        $parse .= '</button>';
        $parse .= '<div class="upload-image" style="display:inline-flex;flex-wrap: wrap;line-height:36px;" id="' . $sid . '">';
        if ($tag['url']) {
            $parse .= '<?php ';
            $parse .= '$__LIST__ = ' . $tag['url'] . ' ? ' . $tag['url'] . ' : [] ;';
            $parse .= '$__LIST__ = is_array($__LIST__) ? $__LIST__ : [$__LIST__];';
            $parse .= ' ?>';
            $parse .= '{volist name="__LIST__" id="val"}';
            $parse .= '<span>{$val}</span>';
            $parse .= '{/volist}';
        }
        $parse .= '</div>';
        $parse .= '<script language="JavaScript" type="text/javascript" src="/static/admin/js/jquery.min.js"></script>';
        $parse .= '<script type="text/javascript">';
        $parse .= 'layui.use([\'upload\'],function(){';
        $parse .= 'var upload = layui.upload;';
        $parse .= 'upload.render({';
        $parse .= 'elem: \'#' . $tag['tagid'] . '\',';
        $parse .= 'url: \'' . $ajaxurl . '\',';
        $parse .= 'accept:\'file\',';
        $parse .= "exts:'" . ($globalConfig['fileValidate_ext'] ?? 'zip|swf|doc|pdf|xls|xlsx|pptx') . "',";
        $parse .= "size:'" . ($globalConfig['fileValidate_size'] ?? '512000') . "',";
        $parse .= 'field:\'imageFile\',';
        $parse .= 'multiple:' . $tag['multiple'] . ',';
        $parse .= 'done: function(res){';
        $parse .= 'if(res.code==0){';
        //判断是否上传多张图片
        if ($tag['multiple'] == 'true') {
            $parse .= '$("#' . $sid . '").append(\'<div class="updiv" style="position: relative;margin-left: 5px;"><input type="hidden" name="' . $tag['name'] . '" value="\'+ res.data.src +\'" /><input type="hidden" name="name_' . $tag['name'] . '" value="\'+ res.data.thumb +\'" /><a href="\'+ res.data.src +\'" target="_blank">\'+ res.data.thumb +\'</a><img width="15px" src="/static/admin/images/x.png" class="pos_close" style="position: absolute;right: 0px;top: 0px;" onclick="pos_close(this)"/></div>\');';
        } else {
            $parse .= '$("#' . $sid . '").html(\'<div class="updiv" style="position: relative;margin-left: 5px;"><input type="hidden" name="' . $tag['name'] . '" value="\'+ res.data.src +\'" /><input type="hidden" name="name_' . $tag['name'] . '" value="\'+ res.data.thumb +\'" /><a href="\'+ res.data.src +\'" target="_blank">\'+ res.data.thumb +\'</a><img width="15px" src="/static/admin/images/x.png" class="pos_close" style="position: absolute;right: 0px;top: 0px;" onclick="pos_close(this)"/></div>\');';
        }
        $parse .= '}';
        $parse .= 'layer.msg(res.msg);';
        $parse .= '},';
        $parse .= 'error: function(){';
        $parse .= 'layer.msg(\'上传失败！\');';
        $parse .= '}';
        $parse .= '});';
        $parse .= '});';
        $parse .= 'var pos_close = function(obj){';
        $parse .= '$(obj).closest(".updiv").remove()';
        $parse .= '}';
        $parse .= '</script>';

        return $parse;
    }

    /**
     * 上传视频标签
     * @param $tag
     * @return string
     */
    public function tagUploadAudiotag($tag)
    {
        global $globalConfig;
        $tag['dir'] = $tag['dir'] ?? '';
        $tag['local'] = $tag['local'] ?? false;
        $ajaxurl = '{$Request.root}/index/upload?type=audio&path=' . $tag['dir'] . '&local=' . $tag['local'];
        $tag['tagid'] = $tag['tagid'] ?? 'fileinput';//标签ID
        $tag['name'] = $tag['name'] ?? 'filename';//上传名称
        $sid = $tag['tagid'] . 'sid';
        $tag['multiple'] = $tag['multiple'] ?? 'false';
        if ($tag['multiple'] == 'true') {
            $tag['name'] .= '[]';
        }
        $parse = '<button type="button" class="pear-btn pear-btn-primary pear-btn-sm upload-image" id="' . $tag['tagid'] . '">';
        $parse .= '<i class="fa fa-image"></i>上传音频';
        $parse .= '</button>';
        $parse .= '<div class="upload-image" style="display:inline-flex;flex-wrap: wrap;" id="' . $sid . '">';
        if ($tag['url']) {
            $parse .= '<?php ';
            $parse .= '$__LIST__ = ' . $tag['url'] . ' ? ' . $tag['url'] . ' : [] ;';
            $parse .= '$__LIST__ = is_array($__LIST__) ? $__LIST__ : [$__LIST__];';
            $parse .= ' ?>';
            $parse .= '{volist name="__LIST__" id="val"}';
            $parse .= '<div class="updiv" style="position: relative;margin-left: 5px;"><input type="hidden" name="' . $tag['name'] . '" value="{$val}" /><a href="{$val}" target="_blank"><audio class="upload-image" style="height: 45px;" controls><source src="{$val}"></audio></a><img width="15px" src="/static/admin/images/x.png" class="pos_close" style="position: absolute;right: 0px;top: 0px;" onclick="pos_close(this)"/></div>';

            $parse .= '{/volist}';
        }
        $parse .= '</div>';
        $parse .= '<script language="JavaScript" type="text/javascript" src="/static/admin/js/jquery.min.js"></script>';
        $parse .= '<script type="text/javascript">';
        $parse .= 'layui.use([\'upload\',\'element\'],function(){';
        $parse .= 'var upload = layui.upload;';
        $parse .= 'var element = layui.element;';
        $parse .= 'let progress = \'' . randString(6) . '\';';
        $parse .= 'upload.render({';
        $parse .= 'elem: \'#' . $tag['tagid'] . '\',';
        $parse .= 'url: \'' . $ajaxurl . '\',';
        $parse .= 'accept:\'audio\',';
        $parse .= "exts:'" . ($globalConfig['audioValidate_ext'] ?? 'mp3|aac') . "',";
        $parse .= "size:'" . ($globalConfig['audioValidate_size'] ?? '204800') . "',";
        $parse .= 'multiple:' . $tag['multiple'] . ',';
        $parse .= 'done: function(res){';
        $parse .= 'if(res.code==0){';
        $parse .= '$(".updiv"+ progress).remove();';
        //判断是否上传多张图片
        if ($tag['multiple'] == 'true') {
            $parse .= '$("#' . $sid . '").append(\'<div class="updiv" style="position: relative;margin-left: 5px;"><input type="hidden" name="' . $tag['name'] . '" value="\'+ res.data.src +\'" /><a href="\'+ res.data.src +\'" target="_blank"><audio class="upload-image" style="height: 45px;" controls><source src="\'+ res.data.src +\'"></audio></a><img width="15px" src="/static/admin/images/x.png" class="pos_close" style="position: absolute;right: 0px;top: 0px;" onclick="pos_close(this)"/></div>\');';
        } else {
            $parse .= '$("#' . $sid . '").html(\'<div class="updiv" style="position: relative;margin-left: 5px;"><input type="hidden" name="' . $tag['name'] . '" value="\'+ res.data.src +\'" /><a href="\'+ res.data.src +\'" target="_blank"><audio class="upload-image" style="height: 45px;" controls><source src="\'+ res.data.src +\'"></audio></a><img width="15px" src="/static/admin/images/x.png" class="pos_close" style="position: absolute;right: 0px;top: 0px;" onclick="pos_close(this)"/></div>\');';
        }
        $parse .= '}';
        $parse .= 'layer.msg(res.msg);';
        $parse .= '},';
        $parse .= 'before: function(obj){';
        if ($tag['multiple'] == 'true') {
            $parse .= '$("#' . $sid . '").append(\'<div class="updiv\'+ progress +\'" style="position: relative;margin-left: 5px;"><div class="layui-progress" style="width: 300px;height: 45px;background-color:antiquewhite;border-radius: 0px;" lay-showPercent="true" lay-filter="filter-demo-\'+ progress +\'"><div class="layui-progress-bar" style="position: absolute;top: 45%;" lay-percent="0%"></div></div></div>\');';
        } else {
            $parse .= '$("#' . $sid . '").html(\'<div class="updiv\'+ progress +\'" style="position: relative;margin-left: 5px;"><div class="layui-progress" style="width: 300px;height: 45px;background-color:antiquewhite;border-radius: 0px;" lay-showPercent="true" lay-filter="filter-demo-\'+ progress +\'"><div class="layui-progress-bar" style="position: absolute;top: 45%;" lay-percent="0%"></div></div></div>\');';
        }
        $parse .= '},';
        $parse .= 'progress: function(n, elem, e){';
        $parse .= 'var percent = n + \'%\';';
        $parse .= 'element.progress("filter-demo-"+ progress, percent);';
        $parse .= '},';
        $parse .= 'error: function(){';
        $parse .= 'layer.msg(\'上传失败！\');';
        $parse .= '}';
        $parse .= '});';
        $parse .= '});';
        $parse .= 'var pos_close = function(obj){';
        $parse .= '$(obj).closest(".updiv").remove()';
        $parse .= '}';
        $parse .= '</script>';
        return $parse;
    }
}